let fs = require('fs');
let Busboy = require('busboy');
let message = require("./message")
let code_message = require("./JsonFileOprate")

module.exports = {
    fileupload: function (req, res) {
        let busboy = new Busboy({headers: req.headers});
        req.pipe(busboy);
        busboy.on('file', function (filedname, file, filename, encoding, mimetype) {
            let writeStream = fs.createWriteStream(`./files/${req.session.staffname}-${new Date().getTime()}-${filename}`);
            file.on('data', function (data) {
                writeStream.write(data);
            })
            file.on('end', function (data) {
                writeStream.end();
            });
        });
        busboy.on('finish', function () {
            res.json(new message("237",null, code_message['237']))
            res.end()
        });
    }
}